#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
typedef pair<int, int> ppi;

int n, k;
vector<ppi> e[N];
int fa[N], son[N], sz[N], dep[N], top[N];
int sum[N];
int a[N];

void dfs1(int u, int father)
{
	fa[u] = father, dep[u] = dep[father] + 1, sz[u] = 1;
	for (int i = 0; i < e[u].size(); i++)
	{
		int s = e[u][i].first;
		if (s == father)
			continue;
		dfs1(s, u);
		sz[u] += sz[s];
		if (sz[son[u]] < sz[s]) son[u] = s;
	}
}

void dfs2(int u, int t)
{
	top[u] = t;
	if (son[u] == 0) return;
	dfs2(son[u], t);
	
	for (int i = 0; i < e[u].size();i++)
	{
		int s = e[u][i].first;
		if (s == fa[u] || s == son[u])
			continue;
		dfs2(s, s);
	}
}

int cla(int u, int v)
{
	while (top[u] != top[v])
	{
		if (dep[top[u]] < dep[top[v]])
			swap(u, v);
		u = fa[top[u]];
	}
	return dep[u] < dep[v] ? u : v;
}

void cal_sum(int u)
{
	for (int i = 0; i < e[u].size(); i++)
	{
		int s = e[u][i].first;
		if (s == fa[u])
			continue;
		int w = e[u][i].second;
		sum[s] = sum[u] + w;
		cal_sum(s);
	}
}

void slove()
{
	//创建无向图
	int u, v, t;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> u >> v >> t;
		e[u].push_back({v, t});
		e[v].push_back({u, t});
	}
	
	//为LCA做准备
	dfs1(1, 0);
	dfs2(1, 1);
	
	//树上前缀和,每个节点到根节点的距离
	cal_sum(1);
	
	//计算总路长
	for (int i = 0; i < k; i++)
		cin >> a[i];
	int ans = 0;
	for (int i = 0; i < k - 1; i++)
	{
		ans += sum[a[i]] + sum[a[i + 1]] - 2 * sum[cla(a[i], a[i + 1])];
	}
	
	
	for (int i = 0; i < k; i++)
	{
		int tmp = ans;
		if (i == 0)
			tmp -= sum[a[i]] + sum[a[i + 1]] - 2 * sum[cla(a[i], a[i + 1])];
		else if (i == k - 1)
			tmp -= sum[a[i]] + sum[a[i - 1]] - 2 * sum[cla(a[i], a[i - 1])];
		else
		{
			tmp -= sum[a[i]] + sum[a[i + 1]] - 2 * sum[cla(a[i], a[i + 1])];
			tmp -= sum[a[i]] + sum[a[i - 1]] - 2 * sum[cla(a[i], a[i - 1])];
			tmp += sum[a[i - 1]] + sum[a[i + 1]] - 2 * sum[cla(a[i - 1], a[i + 1])];
		}
		cout << tmp << " ";
	}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	slove();
	return 0;
}